package exception;

public class GirlFriend {
    private String name;
    private int age;

    public GirlFriend() {
    }

    public GirlFriend(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) throws NameFormatterException {
        int length = name.length();
        if (length < 3 || length > 10) {
            throw new NameFormatterException(name + "姓名不合法！！！");
        }
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeFomatterException {
        if (age < 18 || age > 40) {
            throw new AgeFomatterException(age + "超出范围！！！");
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "GirlFriend{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
